home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SpriteEngine / SE Hunter & Evader / SpriteHanders.c < prev    next >
C/C++ Source or Header  |  1995-03-11  |  3KB  |  105 lines

  1. #include "SpriteTools.h"
  2.  
  3. // SpriteTools.h includes SpriteHandlers.h
  4.  
  5.  
  6. /*** Custom handlers - application dependent ***
  7.  
  8. Edit this as necessary. It should always include the following three routines:
  9.  
  10. MoveSprite: move the sprite
  11.  
  12. HitSprite: handle collisions between two sprites
  13.  
  14. InitSprites: Load all faces and create initial sprites
  15.  
  16. ***/
  17.  
  18.  
  19.  
  20. GrafPtr    firstFace, secondFace, thirdFace;
  21. static    Point    gPlayerPosition;
  22.  
  23.  
  24.  
  25. void MoveSprite(SpritePtr theSprite)
  26. {
  27.     switch (theSprite->kind)
  28.     {
  29.         case playerSprite:
  30.             GetMouse(&theSprite->position);
  31.             gPlayerPosition = theSprite->position;
  32.             break;
  33.         case hunterSprite:
  34.             if (theSprite->position.h < gPlayerPosition.h)
  35.                 theSprite->position.h++;
  36.             else
  37.             if (theSprite->position.h > gPlayerPosition.h)
  38.                 theSprite->position.h--;
  39.             if (theSprite->position.v < gPlayerPosition.v)
  40.                 theSprite->position.v++;
  41.             else
  42.             if (theSprite->position.v > gPlayerPosition.v)
  43.                 theSprite->position.v--;
  44.             break;
  45.         case evaderSprite:
  46.             if (theSprite->position.h < gPlayerPosition.h)
  47.                 theSprite->position.h--;
  48.             else
  49.             if (theSprite->position.h > gPlayerPosition.h)
  50.                 theSprite->position.h++;
  51.             if (theSprite->position.v < gPlayerPosition.v)
  52.                 theSprite->position.v--;
  53.             else
  54.             if (theSprite->position.v > gPlayerPosition.v)
  55.                 theSprite->position.v++;
  56.  
  57. /* Keep this sprite a bit inside the bounds so it doesn't just stand in a corner. */
  58.             if (theSprite->position.h < 50)
  59.                 theSprite->position.h = 50;
  60.             if (theSprite->position.h > gOffScreen->portRect.right - theSprite->face->portRect.right - 50)
  61.                 theSprite->position.h = gOffScreen->portRect.right - theSprite->face->portRect.right - 50;
  62.             if (theSprite->position.v < 50)
  63.                 theSprite->position.v = 50;
  64.             if (theSprite->position.v > gOffScreen->portRect.bottom - theSprite->face->portRect.bottom - 50)
  65.                 theSprite->position.v = gOffScreen->portRect.bottom - theSprite->face->portRect.bottom - 50;
  66.             break;
  67.     }
  68.     
  69.     KeepOnScreen(theSprite);
  70.  
  71. } /*MoveSprite*/
  72.  
  73.  
  74. void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
  75. {
  76.     
  77. } /*HitSprite*/
  78.  
  79.  
  80. void InitSprites()
  81. {
  82.     SpritePtr    theSprite;
  83.  
  84. /*Load all pictures*/
  85.     firstFace = LoadFaceFromCicn(128);            /*cicn resource #128.*/
  86.     secondFace = LoadFaceFromCicn(129);            /*cicn resource #129.*/
  87.     thirdFace = LoadFaceFromCicn(130);            /*cicn resource #130.*/
  88.  
  89. /*Create sprites*/
  90.     theSprite = NewSprite();
  91.     theSprite->kind = hunterSprite;
  92.     theSprite->face = firstFace;
  93.     SetPt(&theSprite->position, 100, 100);
  94.  
  95.     theSprite = NewSprite();
  96.     theSprite->kind = playerSprite;
  97.     theSprite->face = secondFace;
  98.     SetPt(&theSprite->position, 50, 50);
  99.  
  100.     theSprite = NewSprite();
  101.     theSprite->kind = evaderSprite;
  102.     theSprite->face = thirdFace;
  103.     SetPt(&theSprite->position, 150, 150);
  104. } /*InitSprites*/
  105.